function showGif(path,out_path)
   path =  'D:/Projects/AoT/results_archive/render';
   out_path = 'D:\Projects\AoT\results_archive\gif';
   iFile =1;
   iImg = 1;
 
   imgCell = cell(0);
   
   for tilt = 10:10:50
       for pan = 0:30:330
        in_path = [path  '/sample' num2str(iFile)];
        img = createCollage(in_path, pan, tilt);
        %imwrite(img,[out_path '/' num2str(iImg,'%05d') '.png']);
        imgCell{iFile}=img;
        iFile = iFile +1;
        iImg = iImg+1;
   if iFile == 51
       iFile = 1;
   end
       end
   end
   dim = size(img);
   gif = zeros([dim 1 length(imgCell)],'uint8');
   for iFile = 1:length(imgCell)
         gif(:,:,:,iFile)=imgCell{iFile};
   end
   imwrite(gif,[out_path '/movie.gif'],'DelayTime',0.2,'LoopCount',Inf);
   
   %{
   file_list = dir([out_path '/*.png']);
   dim = size(img);
   gif = zeros([dim 1 length(file_list)],'uint8');
   for iFile = 1:length(file_list);
    img = imread([out_path '/' file_list(iFile).name]);
    gif(:,:,:,iFile)=img;
   end
   imwrite(gif,[out_path '/movie.gif'],'DelayTime',0.5);
   %}
end


function canvas=createCollage(path,pan,tilt)
pan_array = [210,270,330];
tilt_array = [50, 30, 10];
center_image = imread([path '/3DMode/_' num2str(tilt) '_' num2str(pan) '.png']);
center_image = rgb2gray(center_image);
w = size(center_image,2);
h = size(center_image,1);

canvas = zeros(3*h,3*w,'uint8');

for row = 1:3
    for col = 1:3
        file_name = [path '/2DMode/_' num2str(tilt_array(row)) '_' num2str(pan_array(col)) '.png'];
        img= rgb2gray(imread(file_name));
        
        % put image into canvas
        canvas((row-1)*h+1:row*h,(col-1)*w+1:col*w)=img;
    end
end

row = 2;
col = 2;
canvas((row-1)*h+1:row*h,(col-1)*w+1:col*w)=center_image;

% add border
border = 255+zeros(h,w,'uint8');
border(1:2,:)=0;
border(end-1:end,:)=0;
border(:,1:2)=0;
border(:,end-1:end)=0;
for row = 1:3
    for col = 1:3
        % put image into canvas
        canvas((row-1)*h+1:row*h,(col-1)*w+1:col*w)=min(canvas((row-1)*h+1:row*h,(col-1)*w+1:col*w),border);
    end
end


end